import { request } from './utils';
import config from './config';

const { qmsServerUrl, authServerUrl } = config;

export default class HomeApi {

  // 获取分厂数据
  static getBranchData = async (): Promise<any[]> => {

    return request({
      method: 'POST',
      url: `${authServerUrl}/api/org/v1/orgs/getByParentAndDemToTree`,
      data: { demId: "" },
    }).then((res) => {
      return res.data.map((item: any) => {
        return { text: item.name, value: item.code }
      })
    });
  }

  // 生产样标签 - 根据条件查询细节
  static getDetailByConditions = async (conditions: object): Promise<any> => {
    return request({
      method: 'POST',
      url: `${qmsServerUrl}/sendSample/v1/querySendSampleInfoProduction`,
      data: {
        qc: conditions
      },
    }).then((res) => {
      const result = res.data.value.records;
      if (result instanceof Array) {
        return result[0]
      } else {
        return {}
      }
    });
  }

  // 获取物料类型数据
  static getTypeData = async (): Promise<any[]> => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve([
          { text: '进厂辅料', value: '1' },
          { text: '出厂辅料', value: '2' },
          { text: '国内铜精矿', value: '3' },
          { text: '国外铜精矿', value: '4' },
          { text: '产成品', value: '5' },
          { text: '中间产品', value: '6' },
        ]);
      }, 0)
    })
  }

  // 生产样标签 - 根据条件查询细节
  static getOtherDetailByConditions = async (conditions: object): Promise<any> => {
    return request({
      method: 'POST',
      url: `${qmsServerUrl}/sendSample/v1/querySendSampleInfo`,
      data: {
        qc: conditions
      },
    }).then((res) => {
      const result = res.data.value.records;
      if (result instanceof Array) {
        return result[0]
      } else {
        return {}
      }
    });
  }
}